package cn.wyj.basic.controller;

import cn.wyj.basic.deo.WechatLoginDto;
import cn.wyj.basic.service.ILoginService;
import cn.wyj.basic.util.AjaxResult;
import cn.wyj.basic.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILoginService loginService;

    /**3
     * 账号登录
     * @param loginVo
     * @return
     */
    @PostMapping("/account")
    public AjaxResult account(@RequestBody @Valid LoginVo loginVo){
        // 调用业务层实现登录，返回值就是token + logininfo用户对象信息
        Map<String, Object> map = loginService.account(loginVo);

        return AjaxResult.me().success(map);
    }
    /**
     * 微信登录
     */
    @PostMapping("/wechat")
    public AjaxResult wechatAccount(@RequestBody WechatLoginDto dto){

        return loginService.wechatAccount(dto);
    }
    /**
     * 微信登录绑定
     */
    @PostMapping("/wechat/binder")
    public AjaxResult wechatBinder(@RequestBody WechatLoginDto dto){

        Map<String, Object> map = loginService.wechatBinder(dto);
        return AjaxResult.me().success(map);
    }
}
